<?php

namespace App;

class MatchLog extends Model
{
    protected $table = 'match_log';

    public function ptcpNum()
    {
    	return $this->hasMany('App\UserMatch', 'match_id', 'id');
    }

    public function winNum()
    {
    	return $this->hasMany('App\UserMatch', 'match_id', 'id')->where(['user_match.result' => $this->match_result]);
    }

    public function isGuess($user)
    {
    	$exist = UserMatch::where(['userid' => $user->userid, 'match_id' => $this->id])->first();
    	return $exist ? true : false;
    }

    public function equalGuess($user)
	{
		$exist = UserMatch::where(['userid' => $user->userid, 'match_id' => $this->id])->first();
		return $exist ? $exist->result : 0;
	} 

} 